package com.zkw.demo.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * Created by Administrator on 2016/4/6.
 */
public class FruitAnnUtils {
    public static void getFruitInfo(Class<?> clazz){
        String strFruitName = "水果名称";
        String strFruitColor = "水果颜色";

        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields){
            if (field.isAnnotationPresent(FruitName.class)){
                FruitName fruitName = field.getAnnotation(FruitName.class);
                strFruitName = strFruitName+fruitName.value();
                System.out.println(strFruitName);
            }
        }
    }

    public static void getFruitFieldAnnotations(Class<?> clazz){
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields){
//            Annotation[] annotations = field.getAnnotations();
            Annotation[] annotations = field.getDeclaredAnnotations();
            System.out.println(field.getName());
            for (Annotation annotation : annotations){
                System.out.println(annotation.annotationType());
            }
        }
    }

    public static void getFruitFields(Class<?> clazz){
        Field[] fieldsD = clazz.getDeclaredFields();
        for (Field field : fieldsD){
            System.out.println("fieldD:"+field.getName());
        }
        Field[] fields = clazz.getFields();
        for (Field field : fields){
            System.out.println("field:"+field.getName());
        }
    }

}
